home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / cdrecord / cd_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-02  |  2.9 KB  |  132 lines

  1. /* @(#)cd_misc.c    1.8 00/07/02 Copyright 1997 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)cd_misc.c    1.8 00/07/02 Copyright 1997 J. Schilling";
  5. #endif
  6. /*
  7.  *    Misc CD support routines
  8.  *
  9.  *    Copyright (c) 1997 J. Schilling
  10.  */
  11. /*
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2, or (at your option)
  15.  * any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; see the file COPYING.  If not, write to
  24.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #include <mconfig.h>
  28. #include <standard.h>
  29. #include <sys/types.h>    /* for caddr_t */
  30. #include <utypes.h>
  31. #include <stdio.h>
  32. #include <schily.h>
  33.  
  34. #include "cdrecord.h"
  35.  
  36. EXPORT    int    from_bcd        __PR((int b));
  37. EXPORT    int    to_bcd            __PR((int i));
  38. EXPORT    long    msf_to_lba        __PR((int m, int s, int f, BOOL force_positive));
  39. EXPORT    BOOL    lba_to_msf        __PR((long lba, msf_t *mp));
  40. EXPORT    void    print_min_atip        __PR((long li, long lo));
  41.  
  42. EXPORT int
  43. from_bcd(b)
  44.     int    b;
  45. {
  46.     return ((b & 0x0F) + 10 * (((b)>> 4) & 0x0F));
  47. }
  48.  
  49. EXPORT int
  50. to_bcd(i)
  51.     int    i;
  52. {
  53.     return (i % 10 | ((i / 10) % 10) << 4);
  54. }
  55.  
  56. EXPORT long
  57. msf_to_lba(m, s, f, force_positive)
  58.     int    m;
  59.     int    s;
  60.     int    f;
  61.     BOOL    force_positive;
  62. {
  63.     long    ret = m * 60 + s;
  64.  
  65.     ret *= 75;
  66.     ret += f;
  67.     if (m < 90 || force_positive)
  68.         ret -= 150;
  69.     else
  70.         ret -= 450150;
  71.     return (ret);
  72. }
  73.  
  74. EXPORT BOOL
  75. lba_to_msf(lba, mp)
  76.     long    lba;
  77.     msf_t    *mp;
  78. {
  79.     int    m;
  80.     int    s;
  81.     int    f;
  82.  
  83. #ifdef    __follow_redbook__
  84.     if (lba >= -150 && lba < 405000) {    /* lba <= 404849 */
  85. #else
  86.     if (lba >= -150) {
  87. #endif
  88.         m = (lba + 150) / 60 / 75;
  89.         s = (lba + 150 - m*60*75)  / 75;
  90.         f = (lba + 150 - m*60*75 - s*75);
  91.  
  92.     } else if (lba >= -45150 && lba <= -151) {
  93.         m = (lba + 450150) / 60 / 75;
  94.         s = (lba + 450150 - m*60*75)  / 75;
  95.         f = (lba + 450150 - m*60*75 - s*75);
  96.  
  97.     } else {
  98.         mp->msf_min   = -1;
  99.         mp->msf_sec   = -1;
  100.         mp->msf_frame = -1;
  101.  
  102.         return (FALSE);
  103.     }
  104.     mp->msf_min   = m;
  105.     mp->msf_sec   = s;
  106.     mp->msf_frame = f;
  107.  
  108.     if (lba > 404849)            /* 404850 -> 404999: lead out */
  109.         return (FALSE);
  110.     return (TRUE);
  111. }
  112.  
  113. EXPORT void
  114. print_min_atip(li, lo)
  115.     long    li;
  116.     long    lo;
  117. {
  118.     msf_t    msf;
  119.  
  120.     if (li < 0) {
  121.         lba_to_msf(li, &msf);
  122.  
  123.         printf("  ATIP start of lead in:  %ld (%02d:%02d/%02d)\n",
  124.             li, msf.msf_min, msf.msf_sec, msf.msf_frame);
  125.     }
  126.     if (lo > 0) {
  127.         lba_to_msf(lo, &msf);
  128.         printf("  ATIP start of lead out: %ld (%02d:%02d/%02d)\n",
  129.             lo, msf.msf_min, msf.msf_sec, msf.msf_frame);
  130.     }
  131. }
  132.